package com.facishare.open.demo;

import com.facishare.open.demo.aop.AopDemoService;
import com.facishare.open.demo.ioc.HelloWorld;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *  demo main 执行.
 * Created by zenglb on 2016/7/19.
 */
@Slf4j
public class AopMainRunner {

    public static void main(String[] args) {
        BeanFactory factory =  new ClassPathXmlApplicationContext("classpath:spring/spring-common.xml");
//        unUseAopDemo((AopDemoService) factory.getBean("aopDemoBaseServiceImpl"));
        useAopDemo((AopDemoService) factory.getBean("aopDemoWithAopServiceImpl"));
    }

    /**
     * 使用原始方式获取执行时间.
     * @param aopDemoService
     */
    private static void unUseAopDemo(AopDemoService aopDemoService) {
        log.info("===原始的方式==================================");
        long start = System.currentTimeMillis();
        aopDemoService.buySomeSauce();
        log.info("call buySomeSauce use : [{}]", (System.currentTimeMillis() - start));
        log.info("=====================================");
    }

    /**
     * 使用aop方式获取执行时间.
     * @param aopDemoService
     */
    private static void useAopDemo(AopDemoService aopDemoService) {
        log.info("===使用aop打印日志==================================");
        aopDemoService.buySomeSauce();
        log.info("=====================================");
    }
}
